#include <cstdio>
using namespace std;

int n, m, u, v, ans, vis[1000005];
int S[1000005];

int getf(int x) {
    if(x == S[x]) return x;        
    return S[x] = getf(S[x]);
}

void merge(int x, int y) {
    int v = getf(y);
    int u = getf(x);
    S[u] = v;
    S[x] = v;
    if (vis[u]) vis[v] = 1;
}

int main() {
	scanf ("%d%d", &n, &m);
	for (int i = 0; i <= n; i++) {
		S[i] = i;
	}
	for (int i = 1; i <= m; i++) {
		scanf ("%d%d", &u, &v);
        if(u==v) continue;
        int x = getf(u);
        int y = getf(v);
        if(x == y){
            vis[x] = 1;
            continue;            
        }
		merge (x, y);
	}
	for (int i = 1; i <= n; i++) {
		if(!vis[i] && i == getf(i)){
            ++ans;
        }
	}
	
	printf ("%d\n", ans);
	return 0;
}
